package cz.studio.stripes.action;

import java.util.List;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import cz.studio.dao.UzivatelDao;
import cz.studio.entity.Uzivatel;
import cz.studio.stripes.action.parent.AbstractAction;

@UrlBinding(value = "/Mas101.action")
public class Mas101 extends AbstractAction{
	private static final String CURRENT_JSP = "/Mas101.jsp";
	
	private List<Uzivatel> uzivatele;
	private UzivatelDao d = new UzivatelDao();
	private Integer id;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@DefaultHandler
	public Resolution addition() {
		UzivatelDao d = new UzivatelDao();
		setUzivatele(d.findAll());
		return new ForwardResolution(CURRENT_JSP);
	}
	
	public Resolution delete() {
		System.out.println(id);
		Uzivatel u = d.find(id);
		d.delete(u);
		return new RedirectResolution(this.getClass());
	}

	public void setUzivatele(List<Uzivatel> uzivatele) {
		this.uzivatele = uzivatele;
	}

	public List<Uzivatel> getUzivatele() {
		return uzivatele;
	}
}